package com.able.mmbs.util;

public class TextConverter {
    public static String strToHex(String str){
        char[] chars = "0123456789ABCDEF".toCharArray();
        StringBuilder sb=new StringBuilder();
        byte[] bs=str.getBytes();
        int bit;
        for(int i=0;i<bs.length;i++){
            bit = (bs[i] & 0x0f0) >> 4;
            sb.append(chars[bit]);
            bit = (bs[i] & 0x0f);
            sb.append(chars[bit]);
        }
        return sb.toString().trim();
    }

    public static String bytesToHex(byte[] bytes) {
        StringBuilder result = new StringBuilder();
        for (byte b : bytes) {
            result.append(String.format("%02X", b));
        }
        return result.toString();
    }


}
